if ($msg eq 'login') {
  $self->{callback} = 'login';
  $self->{calluser} = $user;
  $self->{login}->{part} = 1;
  $self->sendMessage("Please enter your username.");
}
else {
  if (exists $self->{callback}) {
    if ($self->{callback} eq 'login') {
      if ($user eq $self->{calluser}) {
        if ($self->{login}->{part} == 1) {
          $username = $msg;
          $self->{login}->{part} = 2;
          $self->sendMessage("Please enter your password.");
          print $self->{callback};
          print $self->{login}->{part};
          print $msg;
        }
        elsif ($self->{login}->{part} == 2) {
          print $msg;
          $password = md5($msg);
          if (exists $users->{$username}) {
            if ($users->{$username}->{password} eq $password) {
              $session->{$email} = $username;
              $self->sendMessage("Thanks, you are now logged in as $username.");
            }
            else {
              $self->sendMessage("Sorry, wrong password.");
              delete $self->{callback};
              delete $self->{calluser};
              delete $self->{login};
            }
          }
          else {
            $self->sendMessage("Sorry, that user does not exist.");
            delete $self->{callback};
            delete $self->{calluser};
            delete $self->{login};
          }
        }
      }
    }
  }
}